package com.erp.erp_servers.RoleLinkResource.imp;

import com.erp.erp_dao.RoleLinkResource.IRoleLinkResourceDAO;
import com.erp.erp_entitys.RoleLinkResource.RoleLinkResourceEntity;
import com.erp.erp_entitys.RoleLinkResource.RoleLinkResourceEntityExample;
import com.erp.erp_servers.RoleLinkResource.IRoleLinkResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ImpRoleLinkResourceService
 * @Description  角色与资源接口实现类
 * @Author songjizhen
 * @Date 2020-07-11 21:47
 * @Version 1.0
 */
@Service
public class ImpRoleLinkResourceService implements IRoleLinkResourceService {
    @Autowired
    IRoleLinkResourceDAO roleLinkResourceDAO;
    /**
     * 根据条件查询
     *
     * @param record
     * @return
     */
    @Override
    public List<RoleLinkResourceEntity> selectByExample(RoleLinkResourceEntity record) {

        List<RoleLinkResourceEntity> roleLinkResourceEntities = roleLinkResourceDAO.selectByExample(this.getExample(record));
        return roleLinkResourceEntities;
    }

    @Override
    public List<RoleLinkResourceEntity> selectByExample(RoleLinkResourceEntityExample example) {
        return roleLinkResourceDAO.selectByExample(example);
    }

    /**
     * 根据条件查询
     *
     * @param list
     * @param record
     * @return
     */
    @Override
    public List<RoleLinkResourceEntity> selectByExample2(List<String> list, RoleLinkResourceEntity record) {

        RoleLinkResourceEntityExample example=new RoleLinkResourceEntityExample();
        RoleLinkResourceEntityExample.Criteria criteria = example.createCriteria();
        if(record.getId() !=null){
            criteria.andIdEqualTo(record.getId());
        }
        if(record.getResourceCode() !=null){
            criteria.andResourceCodeEqualTo(record.getResourceCode());
        }
        if(record.getRoleCode() !=null){
            criteria.andRoleCodeEqualTo(record.getRoleCode());
        }
      if(list !=null && list.size()>0){
          criteria.andRoleCodeIn(list);
      }
        List<RoleLinkResourceEntity> roleLinkResourceEntities = roleLinkResourceDAO.selectByExample(example);
        return roleLinkResourceEntities;
    }

    /**
     * 根据条件更新
     *
     * @param record
     * @return
     */
    @Override
    public int updateByExampleSelective(RoleLinkResourceEntity record) {
        RoleLinkResourceEntity rlre=new RoleLinkResourceEntity();
        rlre.setId(record.getId());
        int num = roleLinkResourceDAO.updateByExampleSelective(record, this.getExample(rlre));
        return num;
    }

    /**
     * 新增
     *
     * @param record
     * @return
     */
    @Override
    public int insertSelective(RoleLinkResourceEntity record) {
        int num = roleLinkResourceDAO.insertSelective(record);
        return num;
    }

    /**
     * 根据 条件删除
     *
     * @param record
     * @return
     */
    @Override
    public int deleteByExample(RoleLinkResourceEntity record) {

        int num = roleLinkResourceDAO.deleteByExample(this.getExample(record));
        return num;
    }
    private  RoleLinkResourceEntityExample getExample(RoleLinkResourceEntity record){
        RoleLinkResourceEntityExample example=new RoleLinkResourceEntityExample();
        RoleLinkResourceEntityExample.Criteria criteria = example.createCriteria();
        if(record.getId() !=null){
            criteria.andIdEqualTo(record.getId());
        }
        if(record.getResourceCode() !=null){
            criteria.andResourceCodeEqualTo(record.getResourceCode());
        }
        if(record.getRoleCode() !=null){
            criteria.andRoleCodeEqualTo(record.getRoleCode());
        }
        return example;
    }
}
